package com.yunhe.xyxxgl.control;

import com.yunhe.xyxxgl.mode.User;
import com.yunhe.xyxxgl.view.Login;

import java.util.Map;

/**
 * Created by Administrator on 2017/8/8 0008.
 */
public class LoginController {
    private static User currUser;
    public static void loginRoute(int type){
        String[] strInfo = Login.loginUI();
        int iCode = login(strInfo[0],strInfo[1],type);
        switch(iCode){
            case 0 :{
                System.out.println("用户名或密码错误！");
                IndexController.indexRoute();
                break;
            }
            case 1:
                System.out.println("登录成功！");
                AdminHomeController.adminHomeRoute();
        }
    }
    public static int login(String userName,String passWord,int type){
       int  rsCode = 0;
        Map<String,User> userMap = UserController.getAllMap().get(type);
        if(null != userName && null!= passWord && !userName.isEmpty()&& !passWord.isEmpty()){
            if(userMap.containsKey(userName)){
                User user = userMap.get(userName);
                if(user.getPassWord().equals(passWord)){
                    currUser = user;
                    rsCode = 1;
                }
            }
        }
        return rsCode;
    }
    public static void logout(){
        currUser = null;
        System.out.println("已退出系统！");
        IndexController.indexRoute();
    }

    public static User getCurrUser() {
        return currUser;
    }
}
